{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c190d374-2fd6-4492-84c1-1d76bb136296",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/decode-ways/\n",
    "\n",
    "\n",
    "Time Limit Exceeded\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def __init__(self):\n",
    "        #self.dict = {}\n",
    "        #for i, char in enumerate(string.ascii_lowercase):\n",
    "        #    self.dict[i] = char\n",
    "        self.numberList = [str(i) for i in range(1, 27)]\n",
    "        self.counting = 0\n",
    "    \n",
    "    def myDecodeStep(self, numberString):\n",
    "        if (len(numberString) == 0):\n",
    "            self.counting += 1\n",
    "            return\n",
    "        \n",
    "        oneChar = numberString[:1]\n",
    "        if oneChar in self.numberList:\n",
    "            self.myDecodeStep(numberString[1:])\n",
    "        \n",
    "        twoChar = numberString[:2]\n",
    "        if len(twoChar) == 2:\n",
    "            if twoChar in self.numberList:\n",
    "                self.myDecodeStep(numberString[2:])\n",
    "    \n",
    "    def numDecodings(self, s: str) -> int:\n",
    "        #2022.1.5 8:28\n",
    "        self.counting = 0\n",
    "        \n",
    "        self.myDecodeStep(s)\n",
    "        \n",
    "        return self.counting\n",
    "        #2022.1.5 8:35\n",
    "        #debug until 8:43\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "790e0238-e308-47c6-8488-391b922c74d3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e5b1ead-06dc-4591-a985-0fe4746d5991",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "400e7b58-13aa-4e8e-919c-f21a0a1541cd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "a2821fb5-68f6-47e1-9748-5adf0ceb727c",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/decode-ways\n",
    "\n",
    "\n",
    "Success!\n",
    "\n",
    "___\n",
    "\n",
    "\n",
    "Runtime    Beats\n",
    "40 ms      80.41%\n",
    "\n",
    "Memory     Beats\n",
    "15.4 MB    7.43%\n",
    "\n",
    "___\n",
    "\n",
    "Try it again, it solves 99% of the problems you meet in your life.\n",
    "\n",
    "___\n",
    "\n",
    "```python\n",
    "from functools import lru_cache\n",
    "\n",
    "class Solution:\n",
    "    def __init__(self):\n",
    "        self.numberList = [str(i) for i in range(1, 27)]\n",
    "        self.counting = 0\n",
    "    \n",
    "    @lru_cache(maxsize=None, typed=True)\n",
    "    def myDecodeStep(self, numberString: str):\n",
    "        counting = 0\n",
    "\n",
    "        if (len(numberString) == 0):\n",
    "            counting += 1\n",
    "            return counting\n",
    "        \n",
    "        oneChar = numberString[:1]\n",
    "        if oneChar in self.numberList:\n",
    "            counting += self.myDecodeStep(numberString[1:])\n",
    "        \n",
    "        twoChar = numberString[:2]\n",
    "        if len(twoChar) == 2:\n",
    "            if twoChar in self.numberList:\n",
    "                counting += self.myDecodeStep(numberString[2:])\n",
    "        \n",
    "        return counting\n",
    "    \n",
    "    def numDecodings(self, s: str) -> int:\n",
    "        #2022.12.16 5:09\n",
    "        return self.myDecodeStep(s)\n",
    "        #2022.12.16 5:17\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46d12852-73f5-40e7-9eee-b2bb1405492b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
